package com.ismiao.ServletJSP;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LoginServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<head>");
		out.println("<title>登录窗口</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<form id=\"form1\" name=\"form1\" method=\"post\" action=\"login\">");
		out.println("  <p align=\"center\">");
		out.println("    <label>用户");
		out.println("<input type=\"text\" name=\"username\" id=\"username\" />");
		out.println("</label>");
		out.println("</p>");
		out.println("<p align=\"center\">");
		out.println("<label>密码");
		out.println("<input type=\"text\" name=\"password\" id=\"password\" />");
		out.println("</label>");
		out.println("</p>");
		out.println("<p align=\"center\">");
		out.println("<label>");
		out.println("<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"提交\" /> ");
		out.println("</label><label><input type=\"reset\" name=\"reset\" id=\"reset\" value=\"重置\" />");
		out.println("</label>");
		out.println("</p>");
		out.println("</form>");
		out.println("</body>");
		out.println("</html>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
		out.println("<html xmlns='http://www.w3.org/1999/xhtml'>");
		out.println("<HEAD><TITLE>用户信息</TITLE></HEAD>");
		out.println("<h1>你的信息如下：</h1>");
		out.println("<BODY>");
		out.println("<br>用户：" + request.getParameter("username") + "<br>");
		out.println("<br>密码：" + request.getParameter("password") + "<br>");
		out.println("</BODY>");
		out.println("</html>");
	}
}
